package com.apchernykh.rozhlasapp;

import com.apchernykh.ceskyrozhlas.basic.R;
import com.apchernykh.rozhlasapp.ui.RozhlasAppBaseFragmentActivity;
import com.apchernykh.rozhlasapp.utils.ConditionalLog;

import android.os.Bundle;


import android.view.Menu;

public class RozhlasAppActivity extends RozhlasAppBaseFragmentActivity {

	@Override
	protected void onSaveInstanceState(Bundle oStateToSave) {
		oStateToSave.putParcelable("APPLICATION_MODEL_STATE", mApplicationModel);
		ConditionalLog.e("saved pre-downloaded info "+mApplicationModel.mStationsList.size());
		super.onSaveInstanceState(oStateToSave);
	}

	
	@Override
	protected void onCreate(Bundle iSavedInstanceState) {
		super.onCreate(iSavedInstanceState);
		try
		{
		ConditionalLog.e(" created activity "+getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
		}
		catch (Throwable a) {}
		//This is for player testing only
//		try {
//			BackgroundPlaybackService
//			.createBackgroundPlaybackControlIntent(this.getApplicationContext(),
//					true).send();
//		} catch (CanceledException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		//We don't want to re-assign mApplicationModel too frequently, since some background threads 
		//might be refreshing it's members for refresh, so all refreshes will be lost on reassign
		if(iSavedInstanceState!=null && iSavedInstanceState.containsKey("APPLICATION_MODEL_STATE") && mApplicationModel.mStationsList.size() == 0)
		{
			//if there is a saved image of application model, override current model with that in image.
			mApplicationModel = iSavedInstanceState.getParcelable("APPLICATION_MODEL_STATE");
			ConditionalLog.e("recreated pre-downloaded info "+mApplicationModel.mStationsList.size());
		}
		else
		{
			ConditionalLog.e("failed to restore pre-downloaded info "+mApplicationModel.mStationsList.size());
		}
		setContentView(R.layout.activity_main);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu iMenu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, iMenu);
		return true;
	}
}
